import request from '../utils/request';
import { parse } from 'querystring';
import { REST, BASE, RESTS } from '../utils/Api';

/**
 * 用户权限管理 所有的网络请求。
 */

export async function fetchUserData(payload) {
  return request(`${REST}/user/fetchAllUsers`, {
    method: 'POST',
    params: payload,
  });
}

export async function createUser(payload) {
  return request(`${REST}/user/reg`, {
    method: 'POST',
    params: payload,
  });
}
export async function updateUser(payload) {
  return request(`${REST}/user/update`, {
    method: 'POST',
    params: payload,
  });
}

export async function deleteUser(payload) {
  return request(`${REST}/user/delete`, {
    method: 'POST',
    params: payload,
  });
}

//--------------部门-----------------
export async function fetchDepartsData(payload) {
  return request(`${REST}/depart/fetchAllDeparts`, {
    method: 'POST',
    params: payload,
  });
}

export async function createDepart(payload) {
  return request(`${REST}/depart/create`, {
    method: 'POST',
    params: payload,
  });
}
export async function updateDepart(payload) {
  return request(`${REST}/depart/update`, {
    method: 'POST',
    params: payload,
  });
}

export async function deleteDepart(payload) {
  return request(`${REST}/depart/delete`, {
    method: 'POST',
    params: payload,
  });
}

//--------------角色权限-----------------
//获取所有实体和其他可观察权限。
export async function fetchAccessData(payload) {
  return request(`${REST}/role/fetchAccess`, {
    method: 'POST',
    params: payload,
  });
}

export async function fetchRolesData(payload) {
  return request(`${REST}/role/fetchAllRoles`, {
    method: 'POST',
    params: payload,
  });
}

export async function createRole(payload) {
  return request(`${REST}/role/create`, {
    method: 'POST',
    params: payload,
  });
}
export async function updateRole(payload) {
  return request(`${REST}/role/update`, {
    method: 'POST',
    params: payload,
  });
}

export async function deleteRole(payload) {
  return request(`${REST}/role/delete`, {
    method: 'POST',
    params: payload,
  });
}


export async function createCompany(payload) {
  return request(`${REST}/companys/create`, {
    method: 'POST',
    params: payload,
  });
}